package com.lelouch.wetlandweb.service.account;

import com.lelouch.wetlandcommon.domain.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * 用户服务
 *
 * @author lcy
 * @create 2018-09-19 11:35
 */
@Service
public class UserEntityService {

    @Autowired
    private RestTemplate restTemplate;

    private final static String SERVICE_NAME= "wetlandaccount";


    public UserEntity findByUsername(String userName) {
        MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<String, Object>();
        requestBody.add("username", userName);
        HttpHeaders headers = new HttpHeaders();
        headers.set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<MultiValueMap<String, Object>>(requestBody, headers);
        return restTemplate.postForObject("http://" + SERVICE_NAME + "/user/findByUsername", request, UserEntity.class);
    }



}
